1 package activity;
2
3 import java.lang.*;
4 import javax.swing.*;
5 import java.awt.*;
6 import javax.swing.border.*;
7 import java.awt.event.*;
8 import attr.*;
9
10 public class EmployeeActivity extends JFrame implements ActionListener {
11 private JPanel panel;
12 private Employee employee;
13 private JButton buttonLogout, buttonProfile, buttonViewProduct;
14 private JButton buttonViewCustomer, buttonViewEmployee;
15 private JLabel title, header;
16 public EmployeeActivity(String userId) {
17 super("Dashboard - Employee");
18
19 this.setSize(Theme.GUI_WIDTH, Theme.GUI_HEIGHT);
20 this.setResizable(false);
21 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
22 this.setLocationRelativeTo(null);
23
24 employee = new Employee(userId);
25 employee.fetch();
26
27 panel = new JPanel();
28 panel.setLayout(null);
29 panel.setBackground(Theme.BACKGROUND_PANEL);
30
31 title = new JLabel("Welcome, "+userId);
32 title.setBounds(30, 40, userId.length()*30+220,75);
33 title.setOpaque(true);
34 title.setBorder(new EmptyBorder(0,20,0,0));
35 title.setFont(Theme.FONT_TITLE);
36 title.setForeground(Theme.COLOR_TITLE);
37 panel.add(title);
38
39 buttonLogout = new JButton("Logout");
40 buttonLogout.setBounds(Theme.GUI_WIDTH-140, 40, Theme.BUTTON_PRIMARY_WIDTH,30);
41 buttonLogout.setFont(Theme.FONT_BUTTON);
42 buttonLogout.setBackground(Color.WHITE);
43 buttonLogout.setForeground(Theme.COLOR_TITLE);
44 buttonLogout.addActionListener(this);
45 panel.add(buttonLogout);
46
47 buttonProfile = new JButton("My Profile");
48 buttonProfile.setBounds(Theme.GUI_WIDTH-150, 80, 120,30);
49 buttonProfile.setFont(Theme.FONT_BUTTON);
50 buttonProfile.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
51 buttonProfile.setForeground(Theme.COLOR_BUTTON_PRIMARY);
52 buttonProfile.addActionListener(this);
53 panel.add(buttonProfile);
54
55 buttonViewProduct = new JButton("View Product");
56 buttonViewProduct.setBounds(60, 160, 200, 30);
57 buttonViewProduct.setFont(Theme.FONT_BUTTON);
58 buttonViewProduct.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
59 buttonViewProduct.setForeground(Theme.COLOR_BUTTON_PRIMARY);
60 buttonViewProduct.addActionListener(this);
61 panel.add(buttonViewProduct);
62
63 buttonViewCustomer = new JButton("View Customer");
64 buttonViewCustomer.setBounds(60, 190, 200, 30);
65 buttonViewCustomer.setFont(Theme.FONT_BUTTON);
66 buttonViewCustomer.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
67 buttonViewCustomer.setForeground(Theme.COLOR_BUTTON_PRIMARY);
68 buttonViewCustomer.addActionListener(this);
69 panel.add(buttonViewCustomer);
70
71 if (employee.getRole().equals("Manager")) {
72 buttonViewEmployee = new JButton("View Employee");
73 buttonViewEmployee.setBounds(60, 220, 200, 30);
74 buttonViewEmployee.setFont(Theme.FONT_BUTTON);
75 buttonViewEmployee.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
76 buttonViewEmployee.setForeground(Theme.COLOR_BUTTON_PRIMARY);
77 buttonViewEmployee.addActionListener(this);
78 panel.add(buttonViewEmployee);
79 }
80
81 header = new JLabel();
82 header.setBackground(Theme.BACKGROUND_HEADER);
83 header.setOpaque(true);
84 header.setBounds(0, 0, Theme.GUI_WIDTH, 75);
85 panel.add(header);
86
87 this.add(panel);
88 }
89
90 public void actionPerformed(ActionEvent ae) {
91 if (ae.getSource().equals(buttonProfile)) {
92 this.setVisible(false);
93 new MyProfileActivity(this, employee).setVisible(true);
94 }
95 else if (ae.getSource().equals(buttonLogout)) {
96 this.setVisible(false);
97 new LoginActivity().setVisible(true);
98 }
99 else if (ae.getSource().equals(buttonViewProduct)) {
100 this.setVisible(false);
101 new ViewProductActivity(this, employee).setVisible(true);
102 }
103 else if (ae.getSource().equals(buttonViewCustomer)) {
104 this.setVisible(false);
105 new ViewCustomerActivity(this, employee).setVisible(true);
106 }
107 else if (ae.getSource().equals(buttonViewEmployee)) {
108 this.setVisible(false);
109 new ViewEmployeeActivity(this, employee).setVisible(true);
110 }
111 else {}
112 }
113 }